/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Beans;

import java.util.*;

/**
 *
 * @author labib.farag
 */
public class Test {
    public static void main(String[] args) {
   List<String> a = Arrays.asList("a", "c", "b");
   List<String> b = Arrays.asList("a", "b", "c", "d");   
   List<String> c = Arrays.asList("c", "s2", "str2", "str4");
   List<List<String>> lists = new ArrayList<List<String>>();
   lists.add(a);
   lists.add(b);
   lists.add(c);
   
 System.out.println("output 1 " + method1(lists));
 lists.remove(c);
System.out.println("output 2 " + method1(lists));

    }
    public static <T> Set<T> method1(Collection<? extends Collection<T>> collections) {

    Set<T> common = new LinkedHashSet<T>();
    if (!collections.isEmpty()) {
       Iterator<? extends Collection<T>> iterator = collections.iterator();
       common.addAll(iterator.next());
       while (iterator.hasNext()) {
          common.retainAll(iterator.next());
       }
    }
    return common;
}

}
